package cn.pn.project.common;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * 通讯号码验证工具
 */
public class CommunicationNumberVerification {
    /**
     * 验证是否为手机号
     * @param mobiles
     * @return
     */
    public static boolean isMobileNO(String mobiles) {

        Pattern p = Pattern.compile("^1([38][0-9]|4[579]|5[0-3,5-9]|6[6]|7[0135678]|9[89])\\d{8}$");
        Matcher m = p.matcher(mobiles);
        return m.matches();
    }

    /**
     * 固定电话验证带区号
     * @param phoneNumber
     * @return
     */
    public static boolean isTelValid(String phoneNumber) {
        boolean isValid = false;
        // String
        // expression="((^(\\d{2,4}[-_－—]?)?\\d{3,8}([-_－—]+\\d{3,8})?([-_－—]+\\d{1,7})?$)|(^0?1[35]\\d{9}$))";
        String expression = "((^((0\\d{2,3})-)(\\d{7,8})(-(\\d{3,}))?$))";
        CharSequence inputStr = phoneNumber;
        Pattern pattern = Pattern.compile(expression);
        Matcher matcher = pattern.matcher(inputStr);
        if (matcher.matches()) {
            isValid = true;
        }
        return isValid;
    }


    /**
     * 是否是正确的手机号或者座机
     * @param phoneNumber
     * @return
     */
    public static boolean isPhoneNumberValid(String phoneNumber) {
        boolean isValid = false;
        String expression = "((^((0\\d{2,3})-)(\\d{7,8})(-(\\d{3,}))?$)|(^((13[0-9])|(15[^4,\\D])|(18[0-9])|(14[5,7])|(17[0,1,3,5-8]))\\d{8}$))";
        CharSequence inputStr = phoneNumber;
        Pattern pattern = Pattern.compile(expression);
        Matcher matcher = pattern.matcher(inputStr);
        if (matcher.matches()) {
            isValid = true;
        }
        return isValid;
    }


}
